package com.manage.web.controller;

import com.manage.model.dto.OrderDTO;
import com.manage.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单操作接口
 * @author duaiyu
 * @version V1.0
 * @date 2022/5/27
 * 来源：自研
 */
@Slf4j
@Controller
@RequestMapping(value = "/orderController")
public class OrderController {
    @Resource
    OrderService orderService;
    /**
     * 查询订单
     */
    @ResponseBody
    @RequestMapping(value = "/queryOrder", method = RequestMethod.GET)
    public List<OrderDTO> queryOrder(){
        return orderService.queryOrder();
    }

    /**
     * 添加订单
     */
    @ResponseBody
    @RequestMapping(value = "/addOrder", method = RequestMethod.POST)
    public String addOrder(@RequestBody OrderDTO order){
        // 0失败   1成功
        Integer result = orderService.addOrder(order);
        if(result == 0){
            return "添加数据失败";
        }else{
            return "添加数据成功";
        }
    }
}
